package com.product.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.product.common.annotation.Log;
import com.product.common.core.controller.BaseController;
import com.product.common.core.domain.AjaxResult;
import com.product.common.enums.BusinessType;
import com.product.business.domain.MerchantInfo;
import com.product.business.service.IMerchantInfoService;
import com.product.common.utils.poi.ExcelUtil;
import com.product.common.core.page.TableDataInfo;

/**
 * 零售商户信息Controller
 *
 * @author wanghui
 * @date 2022-08-20
 */
@RestController
@RequestMapping("/business/merchant")
public class MerchantInfoController extends BaseController {
    @Autowired
    private IMerchantInfoService merchantInfoService;

    /**
     * 查询零售商户信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:merchant:list')")
    @GetMapping("/list")
    public TableDataInfo list(MerchantInfo merchantInfo) {
        startPage();
        List<MerchantInfo> list = merchantInfoService.selectMerchantInfoList(merchantInfo);
        return getDataTable(list);
    }

    /**
     * @param merchantInfo 商家信息
     * @return {@link TableDataInfo }
     * @Description 查询已审核零售商户信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:merchant:list')")
    @GetMapping("/listpass")
    public TableDataInfo listCheckPass(MerchantInfo merchantInfo) {
        startPage();
        merchantInfo.setMerchantStatus("0");
        List<MerchantInfo> list = merchantInfoService.selectMerchantInfoList(merchantInfo);
        return getDataTable(list);
    }

    /**
     * @param merchantInfo 商家信息
     * @return {@link TableDataInfo }
     * @Description 查询待审核零售商户信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:merchant:list')")
    @GetMapping("/listwait")
    public TableDataInfo listCheckWait(MerchantInfo merchantInfo) {
        startPage();
        merchantInfo.setMerchantStatus("1");
        List<MerchantInfo> list = merchantInfoService.selectMerchantInfoList(merchantInfo);
        return getDataTable(list);
    }

    /**
     * @param merchantInfo 商家信息
     * @return {@link TableDataInfo }
     * @Description 查询待整改零售商户信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:merchant:list')")
    @GetMapping("/listrectify")
    public TableDataInfo listCheckRectify(MerchantInfo merchantInfo) {
        startPage();
        merchantInfo.setMerchantStatus("2");
        List<MerchantInfo> list = merchantInfoService.selectMerchantInfoList(merchantInfo);
        return getDataTable(list);
    }

    /**
     * @param merchantInfo 商家信息
     * @return {@link TableDataInfo }
     * @Description 查询零售商户信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:merchant:list')")
    @GetMapping("/listcancel")
    public TableDataInfo listCheckCancel(MerchantInfo merchantInfo) {
        startPage();
        merchantInfo.setMerchantStatus("3");
        List<MerchantInfo> list = merchantInfoService.selectMerchantInfoList(merchantInfo);
        return getDataTable(list);
    }

    /**
     * 导出零售商户信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:merchant:export')")
    @Log(title = "零售商户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MerchantInfo merchantInfo) {
        List<MerchantInfo> list = merchantInfoService.selectMerchantInfoList(merchantInfo);
        ExcelUtil<MerchantInfo> util = new ExcelUtil<MerchantInfo>(MerchantInfo.class);
        util.exportExcel(response, list, "零售商户信息数据");
    }

    /**
     * 获取零售商户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:merchant:query')")
    @GetMapping(value = "/{merchantId}")
    public AjaxResult getInfo(@PathVariable("merchantId") Long merchantId) {
        return AjaxResult.success(merchantInfoService.selectMerchantInfoByMerchantId(merchantId));
    }

    /**
     * 新增零售商户信息
     */
    @PreAuthorize("@ss.hasPermi('business:merchant:add')")
    @Log(title = "零售商户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MerchantInfo merchantInfo) {
        return toAjax(merchantInfoService.insertMerchantInfo(merchantInfo));
    }

    /**
     * 修改零售商户信息
     */
    @PreAuthorize("@ss.hasPermi('business:merchant:edit')")
    @Log(title = "零售商户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MerchantInfo merchantInfo) {

        return toAjax(merchantInfoService.updateMerchantInfo(merchantInfo));
    }

    /**
     * 删除零售商户信息
     */
    @PreAuthorize("@ss.hasPermi('business:merchant:remove')")
    @Log(title = "零售商户信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{merchantIds}")
    public AjaxResult remove(@PathVariable Long[] merchantIds) {
        return toAjax(merchantInfoService.deleteMerchantInfoByMerchantIds(merchantIds));
    }
}
